package io.lkt.modules.sys.service.impl;

import io.lkt.commons.dynamic.datasource.annotation.DataSource;
import io.lkt.modules.sys.entity.HotVideoInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.lkt.common.utils.PageUtils;
import io.lkt.common.utils.Query;

import io.lkt.modules.sys.dao.ArticleLookDetailLogDBDao;
import io.lkt.modules.sys.entity.ArticleLookDetailLogDBEntity;
import io.lkt.modules.sys.service.ArticleLookDetailLogDBService;


@Service("articleLookDetailLogDBService")
public class ArticleLookDetailLogDBServiceImpl extends ServiceImpl<ArticleLookDetailLogDBDao, ArticleLookDetailLogDBEntity> implements ArticleLookDetailLogDBService {
    @Autowired
    private ArticleLookDetailLogDBDao articleLookDetailLogDBDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<ArticleLookDetailLogDBEntity> page = this.page(
                new Query<ArticleLookDetailLogDBEntity>().getPage(params),
                new QueryWrapper<ArticleLookDetailLogDBEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    @DataSource("logdb")
    public PageUtils queryPageForUserId(Map<String, Object> params) {
        IPage<ArticleLookDetailLogDBEntity> page = this.page(
                new Query<ArticleLookDetailLogDBEntity>().getPage(params),
                new QueryWrapper<ArticleLookDetailLogDBEntity>()
                        .eq("user_id", params.get("userId"))
                        .eq("gzh_code", params.get("gzhCode"))
                        .orderByDesc("id")
        );

        return new PageUtils(page);
    }

    @Override
    public List<ArticleLookDetailLogDBEntity> getUserLookInfo(Map<String, Object> params) {
        return articleLookDetailLogDBDao.getUserLookInfo(params);
    }

    @Override
    public int getUserLookInfoTotal(Map<String, Object> params) {
        return articleLookDetailLogDBDao.getUserLookInfoTotal(params);
    }

    @Override
    @DataSource("logdb")
    public int getUserLookCount(Integer userId, String gzhCode) {
        return articleLookDetailLogDBDao.getUserLookCount(userId, gzhCode);
    }

    @Override
    @DataSource("logdb")
    public List<HotVideoInfo> getHotVideo() {
        return articleLookDetailLogDBDao.getHotVideo();
    }

}
